package com.company.堆栈队列;

import java.util.Scanner;
import java.util.Stack;

/**
 * @author zhangjian
 * @data 2023/4/2
 * @Version 1.0
 * @Descripion
 */
public class AB4逆波兰表达式求值 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String[] tokens = input.nextLine().replace("\"", "").split(",");
        int res = evalRPN(tokens);
        System.out.println(res);
    }

    public static int evalRPN(String[] tokens) {

        Stack<String> stack = new Stack<>();
        for (String s : tokens) {
            if (!"+".equals(s) && !"-".equals(s) && !"*".equals(s) && !"/".equals(s)) {
                stack.push(s);
            } else {
                int num2 = Integer.parseInt(stack.pop());
                int num1 = Integer.parseInt(stack.pop());
                int result = 0;
                switch (s) {
                    case "+":
                        result = num1 + num2;
                        break;
                    case "-":
                        result = num1 - num2;
                        break;
                    case "*":
                        result = num1 * num2;
                        break;
                    case "/":
                        result = num1 / num2;
                        break;
                    default:
                        throw new RuntimeException("运算符不在 + - * / 内");
                }
                stack.push(String.valueOf(result));
            }
        }
        return Integer.parseInt(stack.peek());
    }
}


